package com.yihaodian.cluster;

import java.util.Collection;
import java.util.Map;

import com.yihaodian.index.meta.IndexMeta;
import com.yihaodian.index.meta.routing.RoutingTable;
import com.yihaodian.index.meta.shard.ShardId;

public class ClusterStateUpdate {

	final ClusterStateUpdateType type;

	ClusterState state;

	Collection<Node> nodeList;

	RoutingTable routingTable;

	IndexMeta indexMeta;

	Map<ShardId, String> dataVersion;
	
	ShardMgtChange shardMgtChange;
	
	Node masterNode;

	public ClusterStateUpdate(ClusterStateUpdateType type) {
		this.type = type;
	}

	public ClusterStateUpdateType getType() {
		return type;
	}

	public ClusterState getState() {
		return state;
	}

	public void setState(ClusterState state) {
		this.state = state;
	}

	public Collection<Node> getNodeList() {
		return nodeList;
	}

	public void setNodeList(Collection<Node> nodeList) {
		this.nodeList = nodeList;
	}

	public RoutingTable getRoutingTable() {
		return routingTable;
	}

	public void setRoutingTable(RoutingTable routingTable) {
		this.routingTable = routingTable;
	}

	public IndexMeta getIndexMeta() {
		return indexMeta;
	}

	public void setIndexMeta(IndexMeta indexMeta) {
		this.indexMeta = indexMeta;
	}

	public Map<ShardId, String> getDataVersion() {
		return dataVersion;
	}

	public void setDataVersion(Map<ShardId, String> dataVersion) {
		this.dataVersion = dataVersion;
	}

	public ShardMgtChange getShardMgtChange() {
		return shardMgtChange;
	}

	public void setShardMgtChange(ShardMgtChange shardMgtChange) {
		this.shardMgtChange = shardMgtChange;
	}

	public Node getMasterNode() {
		return masterNode;
	}

	public void setMasterNode(Node masterNode) {
		this.masterNode = masterNode;
	}

	/**
	 * 
	 * @param state
	 * @return
	 */
	public ClusterState newClusterState(ClusterState state) {
		NewClusterStateBuilder builder = NewClusterStateBuilders
				.getBuilder(this.type);

		return builder.newClusterState(this, state);
	}

}
